package com.adinnet.api.content.controller;


import com.adinnet.api.content.model.Content;
import com.adinnet.api.content.model.vo.AdvertisementResp;
import com.adinnet.api.content.service.ContentService;
import com.adinnet.core.JsonResult;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 素材表 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-04
 */
@RestController
@RequestMapping("/api/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 获取最新招聘信息
     * @return
     */
    @GetMapping("getJobOffers")
    public JsonResult getJobOffers() {
        try {
            Content jobOffers = contentService.getJobOffers();
            return JsonResult.ok().put("data",jobOffers);
        }catch (Exception e){
            return JsonResult.error("操作失败");
        }
    }


    /**
     * 2021-02-24 新增每日广告弹窗只弹出一次
     * 接口新增传参 childId,新增返参 isSee（今日是否查看广告）
     * 最新广告查询
     * @return
     */
    @GetMapping("getAdvertisement")
    public JsonResult getAdvertisement(@RequestParam(value = "childId") Integer childId) {
        try {
            AdvertisementResp jobOffers = contentService.getAdvertisement(childId);
            return JsonResult.ok().put("data",jobOffers);
        }catch (Exception e){
            return JsonResult.error("操作失败");
        }
    }

    /**
     * 关于公司
     *
     * @return
     */
    @GetMapping("getCompany")
    public JsonResult getCompany() {
        try {
            Content company = contentService.getCompany();
            if (null == company) {
                return JsonResult.ok().put("data", new JSONObject());
            }
            return JsonResult.ok().put("data", company);
        } catch (Exception e) {
            return JsonResult.error("操作失败");
        }
    }

    /**
     * 豆豆的养成
     *
     * @return
     */
    @GetMapping("getCultivate")
    public JsonResult getCultivate() {
        try {
            Content cultivate = contentService.getCultivate();
            if (null == cultivate) {
                return JsonResult.ok().put("data", new JSONObject());
            }
            return JsonResult.ok().put("data", cultivate);
        } catch (Exception e) {
            return JsonResult.error("操作失败");
        }
    }
}
